<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>添加用户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" th:href="@{../../static/css/weadmin.css}">
</head>

<body>
<div class="weadmin-body">

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">头像</label>
        <div class="layui-input-block">
            <img  id="image" alt=""  th:src="@{(${user.getPictureUrl()})}" style="width: 200px;height: 200px;">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">
            <span class="we-red">*</span>用户ID
        </label>
        <div class="layui-input-inline">
            <input readonly type="text" th:value="${user.getId()}" id="userid" name="username" required="" lay-verify="required" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="username" class="layui-form-label">
            <span class="we-red">*</span>用户名
        </label>
        <div class="layui-input-inline">
            <input readonly type="text" th:value="${user.getUsername()}" id="username" name="username" required="" lay-verify="required" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="L_email" class="layui-form-label">
            <span class="we-red">*</span>邮箱
        </label>
        <div class="layui-input-inline">
            <input readonly th:value="${user.getEmail()}" type="text" id="L_email" name="email" required="" lay-verify="email" autocomplete="off"
                   class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">
            <span class="we-red">*</span>唯一的登入名
        </div>
    </div>
    <div class="layui-form-item">
        <label for="phone" class="layui-form-label">
            <span class="we-red">*</span>手机
        </label>
        <div class="layui-input-inline">
            <input readonly th:value="${user.getTelephone()}" type="text" id="phone" name="telephone" required="" lay-verify="phone" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="phone" class="layui-form-label">
            <span class="we-red">*</span>性别
        </label>
        <div th:switch="${user.getSex()}" class="layui-input-inline">
            <input readonly type="text" name="sex" th:case="1" value="男" class="layui-input">
            <input readonly type="text" name="sex"  th:case="0" value="女" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="phone" class="layui-form-label">
            <span class="we-red">*</span>角色
        </label>
        <div th:switch="${user.getRole()}" class="layui-input-inline">
            <input readonly type="text" th:case="1" value="管理员" class="layui-input">
            <input readonly type="text" th:case="2" value="评委" class="layui-input">
            <input readonly type="text" th:case="3" value="参赛选手" class="layui-input">
            <input readonly type="text" th:case="4" value="观众" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="phone" class="layui-form-label">
            <span class="we-red">*</span>用户状态
        </label>
        <div th:switch="${user.getUserStatus()}" class="layui-input-inline">
            <input readonly type="text" name="status"  th:case="1" value="启用" class="layui-input">
            <input readonly type="text" name="status"  th:case="0" value="注销" class="layui-input">
        </div>
    </div>



    </form>
</div>
<script th:src="@{../../static/layui/layui.js}"></script>
<script th:src="@{../../static/mysource/js/jquery-3.3.1.min.js}"></script>
<script th:src="@{../../static/js/add.js}" type="text/javascript"></script>

<script type="text/javascript">

    function doUpdate(){
        // 使用JQuery发送一个ajax请求
        var name = $("[name='username']").val();
        var email = $("[name='email']").val();
        var role = $("[name='role']").val();
        var sex = $("[name='sex']").val();
        var telephone =  $("[name='telephone']").val();
        console.log(name)

        $.ajax({
            url:"/user/doUpdate",
            dataType:"json",
            type:"post",
            data:{
                "username" :name,"password":pwd,"email":email,"role":role,"sex":sex,"telephone":telephone
            },
            success:function (data){
                if (data.flag){
                    alert(data.msg); location.href='/user/userlist'
                }else {
                    alert(data.msg);
                    location.reload()
                }

            }
        })

    }


</script>


</body>

</html>